<?php
namespace Common\Model;
use Common\Model\CommonModel;
class ModelFieldModel extends CommonModel
{

	protected $_validate = array(
		//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
		array('model_id', 'require', '模型ID不能为空！', 1, 'regex', CommonModel:: MODEL_INSERT  ),
		array('name', 'require', '字段名不能为空！', 1, 'regex', CommonModel:: MODEL_INSERT ),
	);

	protected $_auto = array(
	    array('create_time','mGetTime',CommonModel:: MODEL_INSERT,'callback'),
	    array('status',1,CommonModel:: MODEL_INSERT),
	    array('update_time','mGetTime',CommonModel::MODEL_BOTH,'callback')
	);

	//用于获取时间，格式为2012-02-03 12:12:12,注意,方法不能为private
	function mGetDate() {
		return date('Y-m-d H:i:s');
	}

	function mGetTime(){
		return time();
	}
	
	protected function _before_write(&$data) {
		parent::_before_write($data);
	}

	function getById($id){
		return $this->alias("fields")
			->join(" __MODEL__ as model on model.model_id=fields.model_id ")
			->field("fields.*,model.table_name")->where(array('fields.id'=>$id))->find();
	}

}

